<template>
  <div>
    <div>
      
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="name" label="序号" width="60">
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
        <el-table-column prop="createtime" label="注册时间" width="100">
          <template slot-scope="scope">{{timeFun(scope.row.createtime)}}</template>
        </el-table-column>      
        <el-table-column prop="userPhone" label="手机号"></el-table-column>
        <el-table-column prop="userNick" label="昵称">
          <template slot-scope="scope">
            <span v-if="scope.row.role==2" style="color:red">{{scope.row.userNick}}</span>
            <span v-else>{{scope.row.userNick}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="cityName" label="地区"></el-table-column>
        <el-table-column prop="tui" label="绑定">
          <template slot-scope="scope">
            <div>
              <span v-if="scope.row.userType == 0">未绑定</span>
              <span v-else-if="scope.row.userType == 2">微信</span>
              <span v-else-if="scope.row.userType == 3">QQ</span>
              <span v-else-if="scope.row.userType == 5">微信&QQ</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="tui" label="机型">
          <template slot-scope="scope">
            <div>
              <span v-if="scope.row.deviceType == 1">安卓</span>
              <span v-else-if="scope.row.deviceType == 2">ios</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="dynamicNumber" label="动态"></el-table-column>
        <el-table-column prop="attentionNumber" label="关注"></el-table-column>
        <el-table-column prop="fansNumber" label="粉丝"></el-table-column>
        <el-table-column width="80" label="操作">
          <template slot-scope="scope">
            <div>
            
              <el-button class="addBtn" v-if="scope.row.userStatus==1 && userRole.UR_1301002" type="danger" @click="deletData(scope.row)"> 禁用</el-button>
              <el-button class="addBtn" v-if="scope.row.userStatus==0 && userRole.UR_1301002" type="success" @click="enableUser(scope.row)"> 启用</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
   
    </div>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>

   
   
  </div>
</template>

<script>
  import AddCuser from './AddCuser'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        city:'',
        seachType:'',
        keyword:'',
        tableData: [],
        total:0,
        currentPage4: 1,//分野
        pageIndex:1,
        pageSize:10,
      }
    },
    components:{
      AddCuser
    },
    props:['pardata'],
    
    created() {
      this.getlist()
    },
    methods: {
      getlist() {
        const obj ={
          "pageIndex":this.pageIndex,
          "pageSize":this.pageSize,
         
        };
        if(this.keyword){
          obj.keyword=this.keyword;
        }
        if(this.city){
          obj.city = this.city
        };
        Http.getUserlist(obj)
        .then( res => {
          this.tableData = res.data.data.rows
          this.total = res.data.data.total
          this.dataViedo='';
          this.editStatus = false
        })
        .catch( error => {
          
        })
       
      },
      timeFun(val) {
        return getTime(val)
      },
      getCuser(){
        Http.getCuser()
        .then( res => {
          this.tableData  = res.data.data;
        
        })
        .catch( error => {
          
        })
      },
      
      showUserList(val) {
        this.userData = val;
        
      },
       getdata (evt) {
        },
        datadragEnd (evt) {
            evt.preventDefault();
            
        },
     
      deletData(row){
        this.$confirm('确定禁用此用户吗？','提示',{
          confirmVuttonText:'确定',
          confirmButtonText:'确定'
        }).then( ()=> {
          
          Http.stopUser(row.userId)
          .then(res => {
            if(res.data.code == 200 ) { 
              this.$message.success('用户禁用成功')
              this.getCuser()
            }
          })
        }).catch( ()=> {
          
        })
      },
  
      enableUser(row) { 
        this.$confirm('确定启用此用户吗？','提示',{
          confirmVuttonText:'确定',
          confirmButtonText:'确定'
        }).then( ()=> {
          Http.startUser(row.userId)
          .then(res => {
            if(res.data.code == 200 ) { 
              this.$message.success('用户启用成功')
              this.getlist()
            }
          })
        }).catch( ()=> {
          
        })
      },
      searchFun(obj){
        this.city = obj.city;
        this.seachType = obj.seachType;
        this.keyword = obj.keyword;
        this.pageIndex = 1;
        this.getlist()
      },
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.pageIndex = val;
        this.getlist()
        
      },
    }
  }
</script>
<style  scoped>
.box{
  border-bottom:1px solid red;
}
    .test{
        border:1px solid #ccc;
    }
    .drag-item{
        width: 200px;
        height: 50px;
        line-height: 50px;
        margin: auto;
        position: relative;
        
        background: #ddd;
        margin:20px 5px;
    }
    .ghostClass{
        opacity: 1;
    }
    .bottom{
        width: 200px;
        height: 50px;
        position: relative;
        background: blue;
        top:2px; 
        left: 2px;
        transition: all .5s linear;
    }
</style>
